import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { CaptchaResult, LoginData, ModifyData } from "./types";
// import { usePost } from "@/utils/commonHooks";

/**
 * 登录API
 *
 * @param data {LoginData}
 * @returns
 */
export function loginApi(data: LoginData): AxiosPromise<any> {
  const query = {
    loginName: data.username,
    passWord: data.password,
    // 预留图片验证参数
    // verifyCodeKey: data.verifyCodeKey || "",
    // verifyCode: data.verifyCodeKey || "",
  };

  return request({
    url: "/system/login/doLogin",
    method: "post",
    // data: usePost(query), 增加md5校验
    data: query,
  });
}

/**
 * 注销API
 */
export function logoutApi(): AxiosPromise<any> {
  return request({
    url: "/system/login/logout",
    method: "post",
  });
}

/**
 * 修改密码
 */
export function modifyPasswordApi(data: ModifyData): AxiosPromise<any> {
  return request({
    url: "/system/login/modifyPassword",
    method: "post",
    data: data,
  });
}

/**
 * 重置密码
 */
export function resetPasswordApi(data: ModifyData): AxiosPromise<any> {
  return request({
    url: "/system/sysUser/rest",
    method: "post",
    data: data,
  });
}

/**
 * 获取验证码
 */
export function getCaptchaApi(): AxiosPromise<CaptchaResult> {
  return request({
    url: "/api/v1/auth/captcha",
    method: "get",
  });
}

// 下载
export function downLoadApi(data: any): AxiosPromise<CaptchaResult> {
  return request({
    url: "/system/sysRole/export",
    method: "post",
    data: data,
  });
}
